package io;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class ScannerTest {
	private String filename;
	private ArrayList<String> arraylist;
	private int count;
	public ScannerTest() {
		this.filename = null;
		this.arraylist = new ArrayList<String>();
		this.count = 0;
	}

	public void setfilename(String name) {
		this.filename = name;
	}

	public ArrayList<String> getArrayList() {
		return this.arraylist;
	}
	public String[] getlist()
	{
		String [] list = this.arraylist.toArray(new String[arraylist.size()]);
		return list;
	}
	public void clear()
	{
		this.arraylist.clear();
		
	}
	public int getCount()
	{
		return this.count;
	}
	public void run() {
		
		try {
			Scanner scanner = new Scanner(new File(filename));
			
			while (scanner.hasNext()) {
				String temp = scanner.next();
				int length = temp.length();
				for (int i = 0; i < length; i++) {
					char c = temp.charAt(i);
					String e = String.valueOf(c);
					
					if (!(Character.isLetter(c)||Character.isDigit(c))) {
						String temp2;
						if (i == 0) {
							temp2 = temp.substring(0, 1);
							temp = temp.substring(1);
						} else {
							temp2 = temp.substring(0, i);
							temp = temp.substring(i);
						}

						i = -1;
						length = temp.length();

						arraylist.add(temp2);
					}

				}
				if (temp != null) {
					arraylist.add(temp);
				}
				
			}

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			this.count = arraylist.size();
		}

	}
}
